package Anonymous_study;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
//匿名内部类实现 
public class AnonymousDemo1 {
	public static void main(String[]args){
		Random r = new Random();
		List<Hero> heros = new ArrayList<Hero>();
		for(int i = 0;i<10;i++){
			heros.add(new Hero("Hero"+i,r.nextInt(1000),r.nextInt(1000)));
		}
		 System.out.println("初始化后的集合：");
	        System.out.println(heros.toString());
	        System.out.println("使用匿名类的方式，筛选出 hp>100 && damange<50的英雄");
		Checker newChecker = new Checker(){

			@Override
			public boolean test(Hero h) {
				return h.damage<50&&h.hp>100;
			}
		};
		filter(heros,newChecker);
	}
	private static void filter(List<Hero> a ,Checker newChecker){
		for(Hero temp :a){
			if(newChecker.test(temp)){
				System.out.println(temp);
			}
		}
	}
}
